package com.xlf.service.blog.controller;

import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.common.core.util.page.PageUtils;
import com.xlf.common.core.util.page.redis.PageResult;
import com.xlf.service.blog.domain.Comment;
import com.xlf.service.blog.domain.Friend;
import com.xlf.service.blog.domain.dto.AddCommentDTO;
import com.xlf.service.blog.domain.dto.AddCommentDTO2;
import com.xlf.service.blog.domain.dto.CommentDTO;
import com.xlf.service.blog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/blog/comment")
public class CommentController extends BaseController {

    @Autowired
    CommentService commentService;

    /**
     *
     * @return
     */
    @Anonymous
    @PostMapping("/list")
    public AjaxResult list(@RequestBody CommentDTO commentDTO){
        List<Comment> comments = commentService.getPage(commentDTO);
        return success(getDataTable(comments));
    }

    /**
     * @param comment
     * @return
     */
    @PreAuthorize("@ss.hasPermi('blog:comment:add')")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody AddCommentDTO comment){

        return success(commentService.addComment(comment));
    }

    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermi('blog:comment:delete')")
    public AjaxResult delete(@PathVariable @Validated @NotNull(message = "评论不能为空") Long id){
        commentService.delComment(id);
        return success();
    }
}
